package com.wlsk.license.service.impl;

import com.wlsk.license.cache.UserSessionManager;
import com.wlsk.license.common.enums.OperateLogTempEnum;
import com.wlsk.license.dao.entity.PlateOperateLog;
import com.wlsk.license.dao.mapper.PlateOperateLogMapper;
import com.wlsk.license.service.feign.MerchantFeignClient;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;

@Service
@Slf4j
public class BaseService {

    @Autowired
    private PlateOperateLogMapper plateOperateLogMapper;

    @Autowired
    private MerchantFeignClient merchantFeignClient;

    /**
     * 添加操作日志
     * @param plateId
     * @param uid
     * @param operateLogTempEnum
     * @param isSys 是否系统操作
     * @return
     */
    protected void addOperateLog(Long plateId, Long uid, OperateLogTempEnum operateLogTempEnum, boolean isSys) {
        //操作日志记录保存
        PlateOperateLog plateOperateLog = new PlateOperateLog();
        plateOperateLog.setPlateId(plateId);
        plateOperateLog.setTitle(operateLogTempEnum.getTitle());
        plateOperateLog.setContent(operateLogTempEnum.getContent());
        if(!isSys) {
            plateOperateLog.setCreateId(uid);
            plateOperateLog.setCreateBy(UserSessionManager.getMerchantUser(uid).getNickname());
        } else {
            plateOperateLog.setCreateBy("系统");
        }
        plateOperateLog.setType(operateLogTempEnum.getType());
        plateOperateLog.setCreateTime(LocalDateTime.now());
        plateOperateLogMapper.insert(plateOperateLog);
        log.info("添加操作日志:{}", plateOperateLog);
    }
}
